package com.gxa.xc.rbac.Service.impl.impl;

import com.gxa.xc.rbac.Service.impl.AdminListService;
import com.gxa.xc.rbac.mapper.AdminMapper;
import com.gxa.xc.rbac.pojo.Admin;
import com.gxa.xc.rbac.util.MD5Util;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.List;
@Service
@MapperScan("com.gxa.xc.rbac.mapper")
@SuppressWarnings("all")
public class AdminListServiceImpl implements AdminListService {
    @Autowired
    private AdminMapper adminMapper;

    @Override
    public List<Admin> listData() {
        return adminMapper.findAll();
    }

    @Override
    public void addData(Admin admin) {
        admin.setAdminPwd(MD5Util.MD55(admin.getAdminPwd()));
        admin.setCreateTime(new Timestamp(System.currentTimeMillis()));
        //System.currentTimeMillis()：获取当前系统的时间，而new　Date()所做的事情调用System.currentTimeMillis()，所以
        //利用System.currentTimeMillis()效率要高一点
        adminMapper.save(admin);
    }

    @Override
    public Admin GetAdmin(Integer id) {
        return adminMapper.GetAdmin(id);
    }

    @Override
    public void EditData(Admin admin) {

        adminMapper.EditData(admin);
        System.out.println("输出admin数据：");
        System.out.println(admin.getId());
        System.out.println(admin.getAdminName());
        System.out.println(admin.getUpdateTime());
    }

    @Override
    public void DelData(Integer id) {
        adminMapper.DelData(id);
    }

    @Override
    public void DelAll(String[] ids) {
        adminMapper.DelAll(ids);
    }
}
